import Foundation
import CoreImage

class YCFilterFactory {
    static let shared = YCFilterFactory()
    
    private init() {}
    
    // 创建滤镜实例
    func createFilter(type: FilterType) -> YCFilter {
        let effect: FilterEffect
        let parameters: FilterParameters
        
        switch type {
        case .none:
            effect = BaseFilterEffect()
            parameters = FilterParameters()
            
        case .fujiNC:
            effect = LUTFilterEffect(lutName: "fuji_nc_lut", intensity: 0.85)
            parameters = FilterParameters.fujiNC
            
        case .realistic:
            effect = ComplexFilterEffect(filterType: .realistic)
            parameters = FilterParameters.realistic
            
        case .breeze:
            effect = ComplexFilterEffect(filterType: .breeze)
            parameters = FilterParameters.breeze
            
        case .noir:
            effect = BasicFilterEffect(ciFilterName: "CIPhotoEffectNoir")
            parameters = FilterParameters()
            
        case .vintage:
            effect = BasicFilterEffect(ciFilterName: "CIPhotoEffectProcess")
            parameters = FilterParameters()
            
        case .fade:
            effect = BasicFilterEffect(ciFilterName: "CIPhotoEffectFade")
            parameters = FilterParameters()
            
        case .instant:
            effect = BasicFilterEffect(ciFilterName: "CIPhotoEffectInstant")
            parameters = FilterParameters()
            
        case .dream:
            effect = BasicFilterEffect(ciFilterName: "CIColorControls")
            parameters = FilterParameters.dream
            
        case .dramatic:
            effect = BasicFilterEffect(ciFilterName: "CIColorControls")
            parameters = FilterParameters.dramatic
            
        case .chrome:
            effect = BasicFilterEffect(ciFilterName: "CIPhotoEffectChrome")
            parameters = FilterParameters()
            
        case .tonal:
            effect = BasicFilterEffect(ciFilterName: "CIPhotoEffectTonal")
            parameters = FilterParameters()
            
        case .sepia:
            effect = BasicFilterEffect(ciFilterName: "CISepiaTone")
            parameters = FilterParameters()
            
        case .hasselblad:
            effect = ComplexFilterEffect(filterType: .hasselblad)
            parameters = FilterParameters()
            
        case .hasselbladBW:
            effect = BasicFilterEffect(ciFilterName: "CIColorMonochrome")
            parameters = FilterParameters()
            
        case .hasselbladVintage:
            effect = LUTFilterEffect(lutName: "hasselblad_vintage_lut", intensity: 0.85)
            parameters = FilterParameters()
            
        case .classicFilm:
            effect = LUTFilterEffect(lutName: "classic_film_lut", intensity: 0.9)
            parameters = FilterParameters()
            
        case .filmEra:
            effect = ComplexFilterEffect(filterType: .filmEra)
            parameters = FilterParameters()
            
        case .fx7:
            effect = FX7FilterEffect()
            parameters = FilterParameters()
        }
        
        return YCFilter(type: type, name: type.rawValue, effect: effect, parameters: parameters)
    }
    
    // 获取所有可用滤镜
    func getAllFilters() -> [YCFilter] {
        return FilterType.allCases.map { createFilter(type: $0) }
    }
} 
